

init();
//Statistics
function init() {
    //1.查询进度列表
    queryPorjectList();
}

/**
 * 详情
 */
function queryStatisticsDetail(phone) {
    $.ajax({
        url :   "inspect/statisticsDetails",
        type:   "post",
        data:JSON.stringify({
          /*  pageIndex : pageIndex,*/
            personLiablePhone : phone
        }),
        contentType:"application/json;",
        success:function(data){
            goToLogin(data);
            console.log(data);
            var list = data.data.rows;
            var statisticsDetailHtml  = '<thead>'
                +'<tr>'
                +'<th>检测类型</th>'
                +'<th>检测结果</th>'
                +'<th>修复后结果</th>'
                +'<th>施工小队名称</th>'
                +'<th>分部分项工程名称</th>'
                +'<th>附件</th>'
                +'</tr>'
                +'</thead>'
                +'<tbody>';
            for(var i=0; i<list.length; i++){
                var itpye="";
                if (list[i].inspectState==1){
                    itpye="质量检测";
                }else{
                    itpye="安全检测";
                }
                statisticsDetailHtml = statisticsDetailHtml
                    +'<tr>'
                    +'<td>'
                    +itpye
                    +'</td>'
                    +'<td>'
                    +list[i].inspectStartResult
                    +'</td>'
                    +'<td>'
                    +list[i].inspectEndResult
                    +'</td>'
                    +'<td>'
                    +list[i].teamName
                    +'</td>'
                    +'<td>'
                    +list[i].teamDesc
                    +'</td>'
                    +'<td>'
                    +list[i].fileUrl
                    +'</td>'
                    +'</tr>';
            }
            statisticsDetailHtml = statisticsDetailHtml + +'</tbody>';
            $("#statisticsDetailList").html(statisticsDetailHtml);
        }
    });
}

/**
 * 项目列表
 * @param pageIndex
 */
function queryPorjectList(pageIndex) {
    $.ajax({
        url: prefixUrl + "project/queryList",
        type: "post",
        data: JSON.stringify({pageIndex:pageIndex}),
        contentType: "application/json;",
        success: function (data) {
            var projectHtml = "";
            var list = data.data.rows;
            for(var i=0; i<list.length; i++){
                projectHtml = projectHtml
                    +'<option style="text-align: center;" value="'
                    +list[i].projectId
                    +'">'
                    +list[i].projectName
                    +'</option>';
            }
            $("#projectList").html(projectHtml);
            queryStatisticsList();
        }
    });
}


$("#projectList").change(function () {
    queryStatisticsList();
})



/**
 * 员工列表
 */
function queryStatisticsList(pageIndex) {
    var projectId=$("#projectList").val();
    $.ajax({
        url :   prefixUrl + "inspect/statistics",
        type:   "post",
        data:JSON.stringify({
            pageIndex : pageIndex,
            projectId:projectId
        }),
        contentType:"application/json;",
        success:function(data){
            console.log(data);
            goToLogin(data);
            var list = data.data.rows;
            var statisticsHtml  = '<thead>'
                +'<tr>'
                +'<th>序号</th>'
                +'<th>人员信息</th>'
                +'<th>合格率</th>'
                +'<th>操作</th>'
                +'</tr>'
                +'</thead>'
                +'<tbody>';
            for(var i=0; i<list.length; i++){
                statisticsHtml = statisticsHtml
                    +'<tr>'
                    +'<td>' + (parseInt(i) + 1) + '</td>'
                    +'<td>'
                    +list[i].personLiableName
                    +'</td>'
                    +'<td>'
                    +(list[i].qualificatioRate)*100+'%'
                    +'</td>'
                    +'<td>'
                    +'<button type="button" class="btn btn-info mar-r-5" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo" onclick=queryStatisticsDetail("'
                    + list[i].personLiablePhone
                   /* + list[i].pageIndex*/
                    +'")><i class="glyphicon glyphicon-search"></i></button>'
                    +'</td>'
                    +'</tr>';
            }
            statisticsHtml = statisticsHtml + +'</tbody>';
            $("#statisticsList").html(statisticsHtml);


            var total = data.data.total;
            var remainder = total%20;
            var allNumber = 0;
            if(remainder > 0){
                allNumber = parseInt(total/20) + 1;
            }else{
                allNumber = parseInt(total/20);
            }
            var number = 1;
            var numberHtml = '<li><a onclick=queryStatisticsList('+ "0" +')>«</a></li>';
            for(var i=0; i<allNumber; i++){
                var id = "query-" + i;
                if(i == 0){
                    numberHtml = numberHtml
                        +'<li id="'+ id + '" name="queryList" class="active"><a onclick=queryStatisticsList('+ i +')>' + number + '</a></li>';
                }else{
                    numberHtml = numberHtml
                        +'<li id="'+ id + '" name="queryList"><a onclick=queryStatisticsList('+ i +')>' + number + '</a></li>';
                }
                number++;
            }
            numberHtml = numberHtml + '<li><a onclick=queryStatisticsList('+ (allNumber-1) +')>»</a></li>';
            $("#queryList").html(numberHtml);
        }
    });
}

/*
 *导出
 */

function exportExcel() {
    var projectId = $("#projectList").val();

    $("#projectId").val(projectId);
    $("#exportForm").submit();
    /*$.ajax({
        url: prefixUrl + "excel/export",
        type: "post",
        data: JSON.stringify({
            projectId: projectId
        }),
        contentType: "application/json;",
    });*/
}